import aiohttp
import asyncio

async def getPic(session, url):

    async with session.get(url, verify_ssl=False) as response:

        print('download started: ' + url)
        content = await response.content.read()
        file_name = url.rsplit('-')[-1]
        with open(file_name, mode='wb') as fo:
            fo.write(content)
        print('download completed: ' + url)


async def main():
    urls = [
        'https://n.sinaimg.cn/news/transform/590/w240h350/20201025/c666-kavypmr1059691.png',
        'https://n.sinaimg.cn/fashion/590/w240h350/20201025/429f-kavypmr0688329.jpg',
        'https://n.sinaimg.cn/auto/590/w240h350/20201022/6b85-kavypmq2239246.jpg'
    ]

    async with aiohttp.ClientSession() as session:
        #tasks = [ asyncio.create_task(getPic(session, url)) for url in urls]
        tasks = [ getPic(session, url) for url in urls]

    return tasks
    
# session = aiohttp.ClientSession()
# tasks = [ getPic(session, url) for url in urls]


async def task():
    print('xxxxx')
    count = 10
    while count:
        print('.......................')
        await asyncio.sleep(1)
        count -= 1

if __name__ == '__main__':
    #asyncio.run(main())
    #asyncio.run(task())
    #asyncio.run(asyncio.wait(tasks))
    asyncio.run(asyncio.wait(main()))